package com.example.my.agiftthat.ui.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.my.agiftthat.MvpActivity.ClickActivity;
import com.example.my.agiftthat.R;
import com.example.my.agiftthat.helper.BitmapCircleTransformation;
import com.example.my.agiftthat.helper.RecyclerViewAdapterHelper;
import com.example.my.agiftthat.ui.home.bean.SendBean;

import java.util.List;

/**
 * Created by My on 2016/12/21.
 */

public class SendRecyclerAdapter extends RecyclerViewAdapterHelper<SendBean.DataBean.ItemsBean> {
    private Intent intent=null;
    private String url;
    private int id;
    public SendRecyclerAdapter(Context context, List<SendBean.DataBean.ItemsBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_send, null);
        return new ViewHolder1(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof ViewHolder1) {
            Glide.with(context).load(list.get(position)
                    .getAuthor().getAvatar_url())
                    .transform(new BitmapCircleTransformation(context))
                    .into(((ViewHolder1) holder).imageView_avatar);
            Glide.with(context).load(list.get(position).getCover_image_url())
                    .into(((ViewHolder1) holder).imageView_cover);
            ((ViewHolder1) holder).textView_nickname.setText(list.get(position).getAuthor().getNickname());
            ((ViewHolder1) holder).textView_author_introduction.setText(list.get(position)
                    .getAuthor().getIntroduction());
            ((ViewHolder1) holder).textView_title.setText(list.get(position).getTitle());
            ((ViewHolder1) holder).textView_introduction.setText(list.get(position).getIntroduction());
            ((ViewHolder1) holder).textView_column_title.setText(list.get(position).getColumn().getTitle());
            ((ViewHolder1) holder).textView_like_count.setText(list.get(position).getLikes_count() + "");
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent=new Intent(context, ClickActivity.class);
                url=list.get(position).getUrl();
                id=list.get(position).getColumn().getId();
                intent.putExtra("url", url);
                intent.putExtra("id", id);
                context.startActivity(intent);
            }
        });
    }

    class ViewHolder1 extends RecyclerView.ViewHolder {
        private ImageView imageView_avatar, imageView_cover;
        private TextView textView_nickname, textView_author_introduction, textView_title,
                textView_introduction, textView_column_title, textView_like_count;

        public ViewHolder1(View itemView) {
            super(itemView);
            imageView_avatar = (ImageView) itemView.findViewById(R.id.imageView_avatar);
            imageView_cover = (ImageView) itemView.findViewById(R.id.imageView_cover);
            textView_nickname = (TextView) itemView.findViewById(R.id.textView_nickname);
            textView_author_introduction = (TextView) itemView.findViewById(R.id.textView_author_introduction);
            textView_title = (TextView) itemView.findViewById(R.id.textView_title);
            textView_introduction = (TextView) itemView.findViewById(R.id.textView_introduction);
            textView_column_title = (TextView) itemView.findViewById(R.id.textView_column_title);
            textView_like_count = (TextView) itemView.findViewById(R.id.textView_like_count);
        }
    }
}